package com.zhr.tea.view.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.zhr.tea.R;
import com.zhr.tea.entity.shouye.BodyEnter;
import com.zhr.tea.view.adapter.ShouyeCenterEnterAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ShouyeCenterActivity extends AppCompatActivity {

    @BindView(R.id.product_back)
    ImageView productBack;

    @BindView(R.id.rlv)
    RecyclerView rlv;
    BodyEnter be;
    @BindView(R.id.tv_headname)
    TextView tvHeadname;
    private ShouyeCenterEnterAdapter adapter;
    private List<BodyEnter.ContentBean> data = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shouye_center);
        ButterKnife.bind(this);
        Intent intent = getIntent();
        be = (BodyEnter) intent.getSerializableExtra("cen");
        initView();
        initData();
    }

    private void initData() {
        data.add(be.getContent());
        adapter.notifyDataSetChanged();
        adapter.setListener(new ShouyeCenterEnterAdapter.Listener() {
            @Override
            public void ItemClick(View view, int code) {
                Intent intent = new Intent(ShouyeCenterActivity.this, ProductActivity.class);
                intent.putExtra("id", code);
                startActivity(intent);
            }
        });
    }

    private void initView() {
        adapter = new ShouyeCenterEnterAdapter(this, data);
        rlv.setLayoutManager(new GridLayoutManager(this, 2));
        rlv.setAdapter(adapter);
    }

    @OnClick(R.id.product_back)
    public void onClick() {
        finish();
    }
}
